<%@ page language="java" pageEncoding="UTF-8"%>
<script>
$(function(){
	var getClassUrl = "<%=request.getContextPath()%>/organization/getAllOrganizationClassJson.action";
	$('.icon-reload').click(
		function (){ 
			$('#ocTree').tree({url:'<%=request.getContextPath()%>/organization/getAllOrganizationClassJson.action'});
			$('#ocTree').tree('reload')
		}
	);
	$(".icon-reload").css("cursor","pointer");
	
	$('#ocTree').tree({
		animate: true,
		url: getClassUrl,
		onBeforeExpand:function(node){
			$('#ocTree').tree("options").url=getClassUrl + "?oc.id=" + node.id;
		},
		onClick:function(node){
			var node = $('#ocTree').tree('getSelected');
			$('#orgs').datagrid('reload',{orgClassId:node.id});
			$('#ocTree').tree('expand',node.target);
			$('#orgClassId').val(node.id);//点击商品类别的时候，将当前类别Id设置到查询表单中
		},
		onContextMenu: function(e, node){
			e.preventDefault();
			$('#ocTree').tree('select', node.target);
			$('#mm').menu('show', {
				left: e.pageX,
				top: e.pageY
			});
		}
		
	});
	$('#orgs').datagrid({
			iconCls:'icon-save',
			nowrap: false,
			striped: true,
			collapsible:true,
			url:'<%=request.getContextPath()%>/organization/getOrgsByOrgClassJson.action',
			sortName: 'code',
			sortOrder: 'desc',
			remoteSort: false,
			idField:'code',
			singleSelect:true,
			columns:[[
				{field:'name',title:'名称',width:120},
				{field:'contactPerson',title:'联系人',width:120},
				{field:'phone',title:'联系电话',width:120,rowspan:2,sortable:true,
					sorter:function(a,b){
						return (a>b?1:-1);
					}
				},
				{field:'email',title:'邮箱',width:150,rowspan:2}
			]],
			pageSize:10,  
	        pageList:[5,10,15,20],  
	        fitColumns: true,  
			pagination:true,
			rownumbers:true,
			onDblClickRow:function(){
				selectOrg();
			}
	});
	
	
	
	$('a[name=clearOrgData]').click(function(){
		$('input[name=orgName]').val('');
		$('input[name=contactPerson]').val('');
	})
	
	$('a[name=queryOrg]').click(function(){
		var orgClassId = $('#orgClassId').val();
		var orgName = $('#orgName').val();
		var contactPerson = $('#contactPerson').val();
		if(orgClassId == "" || orgClassId == null)
			$('#orgs').datagrid('reload',{orgName:orgName, contactPerson:contactPerson});
		else
			$('#orgs').datagrid('reload',{orgClassId:orgClassId, orgName:orgName, contactPerson:contactPerson});
	});
	
	$('#orgName').keydown(function(e){
      if(e.keyCode==13) {
    	  var orgName = $('#orgName').val();
    	  $('#orgs').datagrid('reload',{orgName:orgName});
      }
    });
	$('#contactPerson').keydown(function(e){
	      if(e.keyCode==13) {
	    	  var contactPerson = $('#contactPerson').val();
	    	  $('#orgs').datagrid('reload',{contactPerson:contactPerson});
	      }
	});
	
	
});
</script>
<!-- 往来单位弹出框 -->
<div id="orgDlg" class="easyui-dialog" style="width:750px;height:460px"  
        closed="true" buttons="#org-dlg-buttons"> 
        <div class="easyui-layout" fit="true" style="background:#ccc;">
	        <div region="west" iconCls="icon-reload" title="往来单位分类" split="true" style="width:180px;">
				<ul id="ocTree"></ul>
			</div>
			<div region="center" style="overflow:auto;">
				<!-- 条件查询table -->
				<table style="font-size:12px; padding:10px;" border="0">
					<input type="hidden" id="orgClassId" name="orgClassId" value="" />
					<tr>
						<td>
							往来单位名称
						</td>
						<td colspan="2">
							<input type="text" id="orgName" name="orgName" class="easyui-validatebox"  value="${orgName}" />
						</td>
					</tr>
					<tr>
						<td> 联&nbsp;系&nbsp;人
						</td>
						<td>
							<input type="text" id="contactPerson" name="contactPerson" class="easyui-validatebox"  value="${contactPerson}" />
						</td>
						<td>
							<a href="#" class="easyui-linkbutton" name="queryOrg">查询</a>
			 				<a href="#" class="easyui-linkbutton" name="clearOrgData">重置</a>
						</td>
					</tr>
				</table>
				<table id="orgs"></table>
			</div> 
		</div>
		<div id="org-dlg-buttons">  
			<a href="#" class="easyui-linkbutton" iconCls="icon-add" onclick="newOrg()" style="display:none" id="newOrgBtn">新建</a>  
		    <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="selectOrg()">确认</a>  
		    <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#orgDlg').dialog('close')">取消</a>  
		</div> 
</div>
<div id="newOrgDlg" class="easyui-dialog" style="width:500px;height:280px;"  
        closed="true" buttons="#neworg-dlg-buttons">  
    <form id="fm" method="post"> 
    <table border="0" >
            <tr>
            	<td>名称</td>
            	<td><input type="text" id="o.name" name="o.name"  class="easyui-validatebox"  required="true" /></td>
            	<input type="hidden" id="o.id" name="o.id" value="" />
            	<input type="hidden" id="o.oc.id" name="o.oc.id" value="" />
            	<td>类别:</td>
            	<td>
            		<input type="text" name="o.orgClassName" id="o.orgClassName" class="easyui-validatebox" readonly="readonly" onclick="openSelectOC()" required="required"/> 
            	</td>
            </tr> 
            <tr>
            	<td>银行帐号</td>
            	<td><input type="text" id="o.bankNo" name="o.bankNo" required="true" /></td>
            	<td>联系人</td>
            	<td><input type="text" id="o.contactPerson" name="o.contactPerson" required="true" /></td>
            </tr>  
            <tr>
            	<td>联系电话</td>
            	<td><input type="text" id="o.phone" name="o.phone" required="true" /></td>
            	<td>传真</td>
            	<td><input type="text" id="o.fax" name="o.fax" required="true" /></td>
            </tr>
            <tr>
            	<td>邮箱</td>
            	<td><input type="text" id="o.email" name="o.email" required="true" /></td>
            	<td>邮编</td>
            	<td><input type="text" id="o.zipCode" name="o.zipCode" required="true" /></td>
            </tr>
            <tr>
            	<td>地址</td>
            	<td><input type="text" id="o.address" name="o.address" required="true" /></td>
            	<td >备注</td>
            	<td colspan="3"><textarea id="o.note" name="o.note" ></textarea></td>
            </tr>
	</table>  
    </form>
</div>
<div id="neworg-dlg-buttons">  
    <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveOrg()">保存</a>  
    <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#newOrgDlg').dialog('close')">取消</a>  
</div>
<%@ include file="/WEB-INF/pages/common/orgClassSelect.jsp"  %>